package com.easymeeting.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.easymeeting.entity.enums.PageSize;
import com.easymeeting.entity.query.CmbcChargeCodeQuery;
import com.easymeeting.entity.po.CmbcChargeCode;
import com.easymeeting.entity.vo.PaginationResultVO;
import com.easymeeting.entity.query.SimplePage;
import com.easymeeting.mappers.CmbcChargeCodeMapper;
import com.easymeeting.service.CmbcChargeCodeService;
import com.easymeeting.utils.StringTools;


/**
 * 民生银行缴款码 业务接口实现
 */
@Service("cmbcChargeCodeService")
public class CmbcChargeCodeServiceImpl implements CmbcChargeCodeService {

	@Resource
	private CmbcChargeCodeMapper<CmbcChargeCode, CmbcChargeCodeQuery> cmbcChargeCodeMapper;

	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<CmbcChargeCode> findListByParam(CmbcChargeCodeQuery param) {
		return this.cmbcChargeCodeMapper.selectList(param);
	}

	/**
	 * 根据条件查询列表
	 */
	@Override
	public Integer findCountByParam(CmbcChargeCodeQuery param) {
		return this.cmbcChargeCodeMapper.selectCount(param);
	}

	/**
	 * 分页查询方法
	 */
	@Override
	public PaginationResultVO<CmbcChargeCode> findListByPage(CmbcChargeCodeQuery param) {
		int count = this.findCountByParam(param);
		int pageSize = param.getPageSize() == null ? PageSize.SIZE15.getSize() : param.getPageSize();

		SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
		param.setSimplePage(page);
		List<CmbcChargeCode> list = this.findListByParam(param);
		PaginationResultVO<CmbcChargeCode> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
		return result;
	}

	/**
	 * 新增
	 */
	@Override
	public Integer add(CmbcChargeCode bean) {
		return this.cmbcChargeCodeMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Integer addBatch(List<CmbcChargeCode> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.cmbcChargeCodeMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增或者修改
	 */
	@Override
	public Integer addOrUpdateBatch(List<CmbcChargeCode> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.cmbcChargeCodeMapper.insertOrUpdateBatch(listBean);
	}

	/**
	 * 多条件更新
	 */
	@Override
	public Integer updateByParam(CmbcChargeCode bean, CmbcChargeCodeQuery param) {
		StringTools.checkParam(param);
		return this.cmbcChargeCodeMapper.updateByParam(bean, param);
	}

	/**
	 * 多条件删除
	 */
	@Override
	public Integer deleteByParam(CmbcChargeCodeQuery param) {
		StringTools.checkParam(param);
		return this.cmbcChargeCodeMapper.deleteByParam(param);
	}

	/**
	 * 根据ChargeCodeAndAppKey获取对象
	 */
	@Override
	public CmbcChargeCode getCmbcChargeCodeByChargeCodeAndAppKey(String chargeCode, String appKey) {
		return this.cmbcChargeCodeMapper.selectByChargeCodeAndAppKey(chargeCode, appKey);
	}

	/**
	 * 根据ChargeCodeAndAppKey修改
	 */
	@Override
	public Integer updateCmbcChargeCodeByChargeCodeAndAppKey(CmbcChargeCode bean, String chargeCode, String appKey) {
		return this.cmbcChargeCodeMapper.updateByChargeCodeAndAppKey(bean, chargeCode, appKey);
	}

	/**
	 * 根据ChargeCodeAndAppKey删除
	 */
	@Override
	public Integer deleteCmbcChargeCodeByChargeCodeAndAppKey(String chargeCode, String appKey) {
		return this.cmbcChargeCodeMapper.deleteByChargeCodeAndAppKey(chargeCode, appKey);
	}
}